#!/usr/bin/env python

import sys

def mapper():
    bucket={}
    value=''
    for line in sys.stdin:
        line = line.decode('gbk','ignore').strip().encode('utf-8')
        if len(line)>1:
            print >>sys.stderr, line
            (session_id,date_time,modif_tag,query_term,url,satif_tag,act_type) = line.split('\t')
            term=query_term
            term_value=bucket.get(term,['','','','','',''])
            term_value[0]=session_id
            '''
            term_value[1]=term_value[1]+' '+date_time
            term_value[2]=term_value[2]+' '+modif_tag
            term_value[3]=term_value[3]+' '+url
            term_value[4]=term_value[4]+' '+satif_tag
            term_value[5]=term_value[5]+' '+act_type
            '''
            bucket[term]=term_value
        else:
            if len(bucket)<2:
                continue
            terms=bucket.keys()
            for i in range(len(terms)-1):
                for j in range(i+1,len(terms)):
                    print '%s||| %s\t1' % (terms[i],terms[j])
                    
            #for k,v in bucket.iteritems():
            #    print '# %s\t%s' %(k,v)
            bucket={}
            value=''

if __name__ == '__main__':
    mapper()
